package com.magicode.cms.dao.impl;
import java.util.List;
import java.util.Map;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.magicode.cms.dao.IBaseDao;
import com.magicode.common.dao.ICommonDaoService;
@SuppressWarnings("unchecked")
@Transactional
public class BaseDaoImpl<T extends Object> implements IBaseDao<T>{

	@SuppressWarnings("rawtypes")
	@Autowired
	@Qualifier("commonDaoService")
	protected ICommonDaoService commonDaoService;
	
	@Override
	public void createObject(Object obj) throws Exception {
		commonDaoService.save(obj);
	}
	@Override
	public void editObject(Object obj) throws Exception {
		commonDaoService.update(obj);
	}
	@Override
	public Long queryCount(String hql) {
		// TODO Auto-generated method stub
		return commonDaoService.countByHql(hql, null);
	}
	@Override
	public Boolean deleteObject(T obj) throws Exception {
		// TODO Auto-generated method stub
		commonDaoService.delete(obj);
		return null;
	}
	public List<T> queryDataList(String hql,int start,int size)throws Exception{
		if(0==size){
			return  commonDaoService.getListByHQL(hql);
		}
		return  commonDaoService.queryList(hql, start, size, null);
	}
	@SuppressWarnings("rawtypes")
	@Override
	public ICommonDaoService getCommonDaoService() {
		return commonDaoService;
	}

	@SuppressWarnings("rawtypes")
	public void setCommonDaoService(ICommonDaoService commonDaoService) {
		this.commonDaoService = commonDaoService;
	}
	@Override
	public Object getObject(String classname, String id) throws Exception {
		// TODO Auto-generated method stub
		return commonDaoService.getByHQL("select t from "+classname +" t where id= '"+id+"'", null);
	}
	@Override
	public List<T> queryDataList(String hql, Map<String, String> paraMap,
			int start, int size) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public Long queryCount(String hql, Map<String, String> paraMap) {
		// TODO Auto-generated method stub
		return null;
	}
	

	
	
}
